package com.example.wuqujingdianphone.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.example.wuqujingdianphone.R;
import com.example.wuqujingdianphone.adapter.VideoList1Adapter;
import com.example.wuqujingdianphone.adapter.VideoListAdapter;
import com.example.wuqujingdianphone.api.ApiConfig;
import com.example.wuqujingdianphone.base.BaseActivity;
import com.example.wuqujingdianphone.bean.MuluBean;
import com.example.wuqujingdianphone.bean.TiYanguanBean;
import com.example.wuqujingdianphone.bean.VideoListBean;
import com.example.wuqujingdianphone.bean.VideoMoreBean;
import com.example.wuqujingdianphone.utils.SPUtil;
import com.example.wuqujingdianphone.utils.ToastUtil;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 视频列表
 */
public class VideoList1Activity extends BaseActivity {

    @BindView(R.id.toolbar)
    Toolbar mToolbar;
    @BindView(R.id.title)
    TextView mTitle;
    @BindView(R.id.recyclerView)
    RecyclerView mRecyclerView;
    private int pos = 0;
    private String title = "";

    private VideoList1Adapter mAdapter;
    private ArrayList<VideoMoreBean.ChildsBean> listMulu = new ArrayList<>();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_video_list);
        ButterKnife.bind(this);
        listMulu= getIntent().getExtras().getParcelableArrayList("listFrom");
        int sd =listMulu.size();
        title = getIntent().getStringExtra("title");
        mTitle.setText(title);
        mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        Log.i("saasdsf", "--->" + pos);
        initView();
    }

    private void initView() {
        mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
        mRecyclerView.addItemDecoration(new DividerItemDecoration(this, LinearLayout.VERTICAL));
        mAdapter = new VideoList1Adapter(getApplicationContext(), null);
        mAdapter.openLoadAnimation();
        mRecyclerView.setAdapter(mAdapter);
        mAdapter.setNewData(listMulu);
        mAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {

                boolean isLogin = SPUtil.getBoolean(VideoList1Activity.this, "isLogin", false);

                if (isLogin) {
                    Intent intent = new Intent(getApplicationContext(), VideoPlayActivity.class);
                    intent.putExtra("playUrl", ApiConfig.APP_URL + listMulu.get(position).getUrl());
                    intent.putExtra("title", listMulu.get(position).getTitle());
                    startActivity(intent);
                } else {
                    ToastUtil.show("抱歉！您还没有登录哦！");
                }
            }
        });
    }

//    private void initData() {
//        showLoading(this);
//        OkGo.<String>get(ApiConfig.APP_URL + "index.php/Jiekou/shipin")
//                .tag(this)
//                .execute(new StringCallback() {
//                    @Override
//                    public void onSuccess(Response<String> response) {
//                        String ds = response.body();
//                        cancelLoading();
//                        listBeans.clear();
//                        list.clear();
//                        listBeans = GsonUtil.getObjectList(response.body(), VideoListBean.class);
//                        list.addAll(listBeans.get(pos).getMulu());
//                        mAdapter.setNewData(list);
//                    }
//
//                    @Override
//                    public void onError(Response<String> response) {
//                        super.onError(response);
//                        cancelLoading();
//                        ToastUtil.show("加载失败");
//                    }
//                });
//    }


}
